{
  Модуль управления правами, ролями и пользователями

 Управление правами и пользователями

   версия 0.2 март 2011 prodg@ya.ru D.Kondakov
}
unit UsersMngrSystm;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, IIntgrlTypes, IIntgrlBaseCnfg, DataObjcts;

{$i calcconfig.inc}

type
  TacntUsrID = TinlID;
  TacntGrpID = TinlID;

  TDataPermssn = (dpRead, dpCreate, dpDel, dpModify);
  TDataPermssnSet = set of TDataPermssn;
  TScrptPermssn = (spStart, spStop, spCont, spCansel);
  TScrptPermssnSet = set of TScrptPermssn;

  { TUsersMngr }

  TUsersMngr = class(TinlModule)
    procedure GetDefParams(DefParams: TStrings); override;
    function CheckParams: TinlLogicType; override;
    procedure AddDefParams(Params: TStringList); override;
    procedure ResetParams; override;
    procedure ProceedSignal(snlMsg: TinlStringType); override;
    // функции проверки пользователя
    function AuthUser(uName: TinlNameType; uPasswd: TinlStringType): TacntUsrID;
    function ChkUsrDataPermssn(uID: TacntUsrID; dID: TinlID; dPrmssn: TDataPermssn): TinlLogicType;
    function ChkUsrScrptPermssn(uID: TacntUsrID; dID: TinlID; sPrmssn: TScrptPermssn): TinlLogicType;
    // функции разрешений для данных и скриптов
    function GetUsrDataPermssn(uID: TacntUsrID; dID: TinlID): TDataPermssnSet;
    procedure SetUsrDataPermssn(uID: TacntUsrID; dID: TinlID; sPrmssn: TDataPermssnSet);
    function GetUsrScriptPermssn(uID: TacntUsrID; sID: TinlID): TScrptPermssnSet;
    procedure SetUsrScriptPermssn(uID: TacntUsrID; sID: TinlID; sPrmssn: TScrptPermssnSet);
    function GetGrpDataPermssn(gID: TacntGrpID; dID: TinlID): TDataPermssnSet;
    procedure SetGrpDataPermssn(gID: TacntGrpID; dID: TinlID; sPrmssn: TDataPermssnSet);
    function GetGrpScriptPermssn(gID: TacntGrpID; sID: TinlID): TScrptPermssnSet;
    procedure SetGrpScriptPermssn(gID: TacntGrpID; sID: TinlID; sPrmssn: TScrptPermssnSet);
    // функции работы с пользователями и группами
    function GetUserName(uID: TacntUsrID): TinlNameType;
    function GetUserMainGrp(uID: TacntUsrID): TacntGrpID;
    function GetGrpName(gID: TacntGrpID): TinlNameType;
  protected
    function GetUnitVersion: TinlModifctn; override;
    procedure DataInit; override;
    procedure DataDone; override;
    function GetModuleType: TModuleType; override;
  end;

const
  ACCNTmodVer = 1000001;

  accntDefPasswd = 'z1x2c3v4';
  dtaFullAccs: TDataPermssnSet = [dpRead, dpCreate, dpDel, dpModify];
  scrptFullCntrl: TScrptPermssnSet = [spStart, spStop, spCont, spCansel];

implementation

{ TUsersMngr }

procedure TUsersMngr.GetDefParams(DefParams: TStrings);
begin
  DefParams.Append('ACCNT_SYS_AUTH=Использовать системную авторизацию');
end;

function TUsersMngr.CheckParams: TinlLogicType;
begin
  Result := true;
end;

procedure TUsersMngr.AddDefParams(Params: TStringList);
begin
  Params.Append('ACCNT_SYS_AUTH=1');
end;

procedure TUsersMngr.ResetParams;
begin
//  inherited ResetParams;
end;

procedure TUsersMngr.ProceedSignal(snlMsg: TinlStringType);
begin
//  inherited ProceedSignal(snlMsg);
end;

function TUsersMngr.AuthUser(uName: TinlNameType; uPasswd: TinlStringType): TinlID;
begin
  result := noID;
end;

function TUsersMngr.ChkUsrDataPermssn(uID: TacntUsrID; dID: TinlID;
  dPrmssn: TDataPermssn): TinlLogicType;
begin
  result := true;
end;

function TUsersMngr.ChkUsrScrptPermssn(uID: TacntUsrID; dID: TinlID;
  sPrmssn: TScrptPermssn): TinlLogicType;
begin
  result := true;
end;

function TUsersMngr.GetUsrDataPermssn(uID: TacntUsrID; dID: TinlID
  ): TDataPermssnSet;
begin
  result := dtaFullAccs;
end;

procedure TUsersMngr.SetUsrDataPermssn(uID: TacntUsrID; dID: TinlID;
  sPrmssn: TDataPermssnSet);
begin

end;

function TUsersMngr.GetUsrScriptPermssn(uID: TacntUsrID; sID: TinlID
  ): TScrptPermssnSet;
begin
  result := scrptFullCntrl;
end;

procedure TUsersMngr.SetUsrScriptPermssn(uID: TacntUsrID; sID: TinlID;
  sPrmssn: TScrptPermssnSet);
begin
  //
end;

function TUsersMngr.GetGrpDataPermssn(gID: TacntGrpID; dID: TinlID
  ): TDataPermssnSet;
begin
  result := dtaFullAccs;
end;

procedure TUsersMngr.SetGrpDataPermssn(gID: TacntGrpID; dID: TinlID;
  sPrmssn: TDataPermssnSet);
begin
  //
end;

function TUsersMngr.GetGrpScriptPermssn(gID: TacntGrpID; sID: TinlID
  ): TScrptPermssnSet;
begin
  result := scrptFullCntrl;
end;

procedure TUsersMngr.SetGrpScriptPermssn(gID: TacntGrpID; sID: TinlID;
  sPrmssn: TScrptPermssnSet);
begin
  //
end;

function TUsersMngr.GetUserName(uID: TacntUsrID): TinlNameType;
begin
  result := 'Инженер';
end;

function TUsersMngr.GetUserMainGrp(uID: TacntUsrID): TacntGrpID;
begin
  result := noID;
end;

function TUsersMngr.GetGrpName(gID: TacntGrpID): TinlNameType;
begin
  result := 'Технологи';
end;

function TUsersMngr.GetUnitVersion: TinlModifctn;
begin
  Result := ACCNTmodVer;
end;

procedure TUsersMngr.DataInit;
begin
//  inherited DataInit;
end;

procedure TUsersMngr.DataDone;
begin
//  inherited DataDone;
end;

function TUsersMngr.GetModuleType: TModuleType;
begin
  Result := mACCNT;
end;

end.

